package libra.forConsumer;

import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import libra.controller.BuildResp;

@RestController
@RequestMapping("forConsumer")
public class ForConsumerController {
	
	@Value( "#{'${server.servlet.context-path}'.concat('[port(${server.port})]')}" )
	String identity;
	@PostConstruct
	public void after() {
		BuildResp.provider = identity;
	}
	
	// 测试QPS流控
	@RequestMapping("testFlowQps")
	public Map<String, String> testFlowQps( Boolean exFlag ){
		if( exFlag ) {
			int i = 1/0;
		}
		return BuildResp.createResp("success..testFlowQps...");
	}
	
	// 测试Degrade降级
	@RequestMapping("testDegrade")
	public Map<String, String> testDegrade( Boolean exFlag, Integer exType ) throws Exception{
		if( exFlag ) {
			// 测试慢比例调用
			if( exType == 1 ) {
				Thread.sleep(1000);
			}
			// 测试异常比例、异常数
			if( exType == 2 ) {
				int i = 1/0;
			}
		}
		return BuildResp.createResp("success..testDegrade...");
	}
}
